package routers

import (
	"gocamp2022/shutdown/gcache"
	"gocamp2022/shutdown/utils"
	"net/http"
)

// InitRouter 初始化路由-对外暴露
func InitRouter(srv *http.ServeMux) {
	srv.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello world"))
	})

	srv.HandleFunc("/cache/put", func(writer http.ResponseWriter, request *http.Request) {
		// 随机产生一个key
		key := "key_" + utils.RandStringCrypto(10)
		// 随机产生一个value
		value := "value_" + utils.RandStringCrypto(24)
		// 将key和value放入缓存
		gcache.Gcache.Store(key, value)
		writer.Write([]byte("put key: " + key + " value: " + value))
	})
}

// InitRouterInner 初始化路由-内部使用
func InitRouterInner(srv *http.ServeMux) {
	srv.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		writer.Write([]byte("hello world from inner"))
	})

}
